package java_0629;


public class ThreadDemo19 {
    static class NotifyTask implements Runnable{
        private Object locker = null;
        public NotifyTask(Object locker) {
            this.locker = locker;
        }

        @Override
        public void run() {
         //进行Notify的线程
            synchronized (locker){
                System.out.println("notify开始");
                locker.notify();
                System.out.println("notify结束");
            }
        }
    }
    static class WaitTask implements Runnable {
        private Object locker = null;

        public WaitTask(Object locker) {
            this.locker = locker;
        }

        @Override
        public void run() {
            //进行wait的线程
            synchronized (locker) {
                System.out.println("wait开始");
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("wait结束");
            }
        }
    }
    public static void main(String[] args) throws InterruptedException {
        Object locker = new Object();
        Thread t1 = new Thread(new WaitTask(locker));
        Thread t2 = new Thread(new NotifyTask(locker));

        t1.start();
        Thread.sleep(3000);
        t2.start();
    }
}
